package com.hexacta.hrs;

import static org.springframework.beans.factory.config.AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Selenium Regression Tests.
 */
public class RegressionTestI {

    private static final SeleniumServerFixture seleniumFixture = new SeleniumServerFixture();

    private static final TomcatFixture tomcatFixture = new TomcatFixture();

    private static final DatabaseFixture databaseFixture = new DatabaseFixture();

    private static UserRobot user;

    @BeforeClass
    public static void setUpClass() throws Exception {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-st-config.xml");
        context.getAutowireCapableBeanFactory().autowireBeanProperties(databaseFixture, AUTOWIRE_BY_NAME, true);
        databaseFixture.setApplicationContext(context);
        context.getAutowireCapableBeanFactory().autowireBeanProperties(tomcatFixture, AUTOWIRE_BY_NAME, true);

        databaseFixture.setUp();
        seleniumFixture.setUp();
        tomcatFixture.setUp();

        user = new UserRobot(databaseFixture.getTestDataContext());
    }

    @AfterClass
    public static void tearDownClass() {
        if (tomcatFixture != null) {
            tomcatFixture.tearDown();
        }
        if (seleniumFixture != null) {
            seleniumFixture.tearDown();
        }
        if (databaseFixture != null) {
            databaseFixture.tearDown();
        }
    }

    @After
    public void tearDown() {
        user.logoutQuietly();
    }

    @Test
    public void testAddTimeOff() throws Exception {
        user.login();
        user.navigateToTimeOffMenu();
        user.addTimeOff();
    }

    @Test
    public void testLogin() throws Exception {
        user.login();
    }

}
